/**
 * ajax带确认框删除
 * get传参
 */

    $(document).on('click','.ajax-delete',function () {
        var $url = this.href,
            $info = $(this).data('info');
        layer.confirm($info, {icon: 3}, function (index) {
            layer.close(index);
            $.get($url, function (data) {
                if (data.status) {
                    layer.alert(data.info, {icon: 6}, function (index) {
                        layer.close(index);
                        window.location.href = data.url;
                    });
                } else {
                    layer.alert(data.info, {icon: 5}, function (index) {
                        layer.close(index);
                    });
                }
            }, "json");
        });
        return false;
    });

/* get执行并返回结果，执行后带跳转 */
$(function () {
    $('.rst-btn').click(function () {
        var $url = this.href;
        $.get($url, function (data) {
            if (data.status) {
                layer.alert(data.info, {icon: 6}, function (index) {
                    layer.close(index);
                    window.location.href = data.url;
                });
            } else {
                layer.alert(data.info, {icon: 5}, function (index) {
                    layer.close(index);
                });
            }
        }, "json");
        return false;
    });
});
/**
 * 表单提交
 */
$(function () {
    $('.ajax-form').ajaxForm({
        success: complete, // 这是提交后的方法
        dataType: 'json'
    });
});
function complete(data) {
    if (data.status == 1) {
        layer.alert(data.info, {icon: 6}, function (index) {
            layer.close(index);
            window.location.href = data.url;
        });
    } else {
        layer.alert(data.info, {icon: 5}, function (index) {
            layer.close(index);
            window.location.href = data.url;
        });
    }
}
/**
 * 图片上传
 * @return 图片预览效果
 */
$(function () {
    $(".up_img").change(function () {
        var objUrl = getObjectURL(this.files[0]);
        if (objUrl) {
            $("#pic").attr("src", objUrl);
        }
    });
})
function getObjectURL(file) {
    var url = null;
    if (window.createObjectURL != undefined) { // basic
        $("#oldcheckpic").val("nopic");
        url = window.createObjectURL(file);
    } else if (window.URL != undefined) { // mozilla(firefox)
        $("#oldcheckpic").val("nopic");
        url = window.URL.createObjectURL(file);
    } else if (window.webkitURL != undefined) { // webkit or chrome
        $("#oldcheckpic").val("nopic");
        url = window.webkitURL.createObjectURL(file);
    }
    return url;
}

/**
 * 多图上传
 * @return 图片预览效果
 */
$(function () {
    $(".multi_img").change(function () {
        var objUrl = getObjectURL(this.files[0]);
        if (objUrl) {
            $(this).next().attr("src", objUrl);
        }
    });
})
